package com.luyuan.crm.promotion.web;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.faces.model.SelectItem;

import org.springframework.stereotype.Component;

import com.luyuan.crm.product.model.Product;
import com.luyuan.crm.product.service.ProductService;
import com.ruijie.web.jsf.provider.SelectItemsProvider;

@Component("promotionProductProvider")
public class PromotionProductProvider implements SelectItemsProvider {
    @Resource(name = "productService")
    private ProductService productService;

    @Override
    public List<SelectItem> getSelectItems(Object... arg0) {
        List<Product> products = productService.find("from Product where enabled = true");

        List<SelectItem> items = new ArrayList<SelectItem>();
        for (Product product : products) {
            SelectItem item = new SelectItem(product, product.getName());
            items.add(item);
        }
        return items;
    }

}
